package top.metaspace.concurrent.threadpool;

import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author panjun
 * @date 2018/6/26.
 */
public class ScheduledThreadPoolExecutorDemo {
	public static void main(String[] args){
		ScheduledThreadPoolExecutor scheduled = new ScheduledThreadPoolExecutor(10);
		//延迟1000执行
		//返回值可以用于获取执行结果
		ScheduledFuture scheduledFuture = scheduled.schedule(new Runnable() {
			@Override
			public void run() {
				System.out.println(System.currentTimeMillis());

			}
		},1000L,TimeUnit.MILLISECONDS);

		//每隔40毫秒执行一次
		scheduled.scheduleAtFixedRate(new Runnable() {
			@Override
			public void run() {
        System.out.println("执行:"+System.currentTimeMillis());
			}
		}, 0, 40, TimeUnit.MILLISECONDS);



	}

}
